\chapter{学科特殊环境}

\section{代码}
% the listings package

\subsection{行内代码}

一共有三种方法可以生成行内代码：
\begin{itemize}
    \item 使用 \texttt{\textbackslash verb} 抄录环境：\verb!<Your code>!
    \item 使用 \texttt{\textbackslash lstinline} 行内代码环境：\lstinline[basicstyle=\tt]+<Your code>+
    \item 使用简写的行内代码环境：|<Your code>|
\end{itemize}
在前两者中，只要使用在代码中未出现的符号将代码包括在内即可。

\subsection{代码块}

代码示例。在构建 \textsf{njuvisual} 宏包时，使用 inkscape 程序从矢量图导出的 \textsf{tikz} 曲线代码并不美观，需要缩进、对齐，因而拜托鄢老师编写了如下的 Python 脚本。
\begin{lstlisting}[language=Python,morekeywords={startswith,endswith,split,strip,join,find,append,replace}]
def deal_tuple(s):
if s.startswith("("):
    # s be like (x,y)
    return "( {0:>9}, {1:>9} )".format(*s[1:-1].split(","))
else:
    return s


indent = len(".. controls (    0.0000,    0.0000 )") - 1


def deal_line(s):
    s = " ".join(map(deal_tuple, s.split()))
    if s.find(")") != -1:
        s = " " * (indent - s.find(")")) + s
    return s


try:
    while True:
        s = input().strip()
        if s.startswith("\path"):
            l = []
            while not s.endswith(";"):
                l.append(s)  # use this instead of += for speedup
                s = input().strip()
            l.append(s[:-1])  # remove trailing ;
            # NOTE: all strings in l should be newline-free
            head, rp, body = " ".join(l).replace(".. controls", "\n.. controls").replace(
                "--", "\n--").replace(")(", ")\n(").replace("cycle(", "cycle\n(").partition("]")

            # force the program to keep newlines added manually
            result = "\n".join(map(deal_line, body.splitlines()))

            print(head, rp, "\n", result, ";", sep="")
        else:
            print(s)
except EOFError as e:
    pass
\end{lstlisting}

\section{算法块}

使用 {algorithm} 和 {algorithmic} 的算法示例\footnote{两者均位于 \textsf{algorithms} 下}。

\begin{algorithm}[htbp]
    \caption{Lanczos Algorithm}
    \begin{algorithmic}
        \STATE - Choose an initial state $\vec{b}_0$ and a maximum iteration number $m$
        \FOR{$n=0,\ldots m$}
        \STATE - Construct the space $K = \spn\{\vec{b}_0 , \ldots \vec{b}_n \}$
        \STATE - Obtain $\vec{C} = \hat{H} \vec{b}_n$
        \IF{$\vec{C} \in K$}
        \STATE Set $\vec{b}_{n+1}$ to a random vector orthogonal to $K$
        \ELSE
        \STATE Orthogonalize $\vec{C}$ against $K$, yielding $\vec{b}_{n+1}$
        \ENDIF\ENDFOR
    \end{algorithmic}
\end{algorithm}


\section{物理}
% the physics package

\begin{equation}
    \expval{A}{\Psi}
\end{equation}


\section{化学}

化学式：
\begin{equation}
    \frac{\varphi_{\ce{Ag +AgCl, Cl^{-}}}^{\ominus}-\varphi_{\ce{Ag +AgCl, Cl^{-}}}}{\varphi_{\ce{Ag +AgCl, Cl^{-}}}^{\ominus}}=\frac{0.0623}{0.8035}\times100\%=7.76\%
\end{equation}

化合物结构：
\begin{figure}[H]
  \centering
  \chemfig{[:18]*5(-=(-CHO)-N-=)}
\end{figure}